package com.bigger.controller;

import com.bigger.dto.ShoppingCarDTO;
import com.bigger.entity.ShoppingCar;
import com.bigger.result.Result;
import com.bigger.service.ShoppingCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shopping")
public class ShoppingCarController {
    @Autowired
    private ShoppingCarService shoppingCarService;
    @GetMapping("/get")
    public Result<List<ShoppingCar>> get(){
        List<ShoppingCar> shoppingCars=shoppingCarService.get();
        return Result.success(shoppingCars);
    }
    @PostMapping("/add")
    public Result<String> add(@RequestBody ShoppingCarDTO shoppingCarDTO){
        shoppingCarService.add(shoppingCarDTO);
        return Result.success("添加成功");
    }
    @PutMapping("/update")
    public Result<String> update(@RequestBody ShoppingCarDTO shoppingCarDTO){
        shoppingCarService.update(shoppingCarDTO);
        return Result.success("修改成功");
    }
    @DeleteMapping("/delete")
    public Result<String> delete(Long id){
        shoppingCarService.delete(id);
        return Result.success("删除成功");
    }
    @GetMapping("/get/{id}")
    public Result<ShoppingCar> getById(@PathVariable("id") Long id){
        ShoppingCar shoppingCar=shoppingCarService.getById(id);
        return Result.success(shoppingCar);
    }
}
